package com.sky.web.app;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
public class AppSetmealController {

    @Autowired
    private SetmealService setmealService;

    //根据分类Id查询套餐列表
    @Cacheable(value = "setmealCache", key = "#categoryId")
    @GetMapping("/list")
    public Result findList(Long categoryId) {//1.接收参数
        //2.封装dto
        SetmealPageDTO setmealPageDTO = new SetmealPageDTO();
        setmealPageDTO.setCategoryId(categoryId);
        setmealPageDTO.setStatus(1);//状态
        //3.调用service查询
        List<SetmealVO> list =
                setmealService.findList(setmealPageDTO);
        //4.返回结果
        return Result.success(list);
    }

    //根据套餐id查询菜品列表
    @GetMapping("/dish/{id}")
    public Result findDishItemsBySetMealId(@PathVariable("id") Long id) {
        List<DishItemVO> dishItemVOList = setmealService.findDishItemsBySetMealId(id);
        return Result.success(dishItemVOList);
    }
}
